package com.hzqy.persistence.dao.itf;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.apache.ibatis.session.SqlSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.hzqy.persistence.dao.core.PersistenceDao;
import com.hzqy.web.vo.CmCatalogVo;
import com.hzqy.web.vo.CmContentVo;
import com.hzqy.web.vo.PmsOrgVo;
import com.hzqy.web.vo.SysConfigVo;
import com.hzqy.web.vo.UserHistoryVo;
import com.hzqy.web.vo.YxtAcountInfoVo;
import com.hzqy.web.vo.YxtAlbumVo;
import com.hzqy.web.vo.YxtJiaoFuResVo;
import com.hzqy.web.vo.YxtLuBoResVo;
import com.hzqy.web.vo.YxtMsCollectVo;
import com.hzqy.web.vo.YxtMsMskcVo;
import com.hzqy.web.vo.YxtMsSpzxVo;
import com.hzqy.web.vo.YxtNmsykClassRoomCourseVo;
import com.hzqy.web.vo.YxtNmsykCourseVo;
import com.hzqy.web.vo.YxtNmsykLessonVo;
import com.hzqy.web.vo.YxtNmsykMenuVo;
import com.hzqy.web.vo.YxtNmsykTopTeacherVo;
import com.hzqy.web.vo.YxtSchoolVo;

@Repository
public class YxtItfDao extends PersistenceDao<YxtAcountInfoVo,Integer> {
	protected final Logger LOG = LoggerFactory.getLogger(getClass());
	
	public PmsOrgVo  selectOrgOfContent(String serverid, int f_ccc_catalogid){
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("f_ccc_catalogid", f_ccc_catalogid);
		map.put("serverid", serverid);
		return getSqlSession().selectOne(this.getNamespace() + "selectOrgOfContent", map);
	}
	
	public YxtAcountInfoVo selectYxtAccountInfo(String serverId,String schoolName, int f_ccc_catalogid){
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("serverId", serverId);
		map.put("schoolName", schoolName);
		map.put("f_ccc_catalogid", f_ccc_catalogid);
		return getSqlSession().selectOne(this.getNamespace() + "selectYxtAccountInfo", map);
	}
	
	public List<YxtJiaoFuResVo> getYxtJiaoFuGrade(String schoolid,int f_ccc_catalogid) {
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("schoolid", schoolid);
		map.put("f_ccc_catalogid", f_ccc_catalogid); 
		return getSqlSession().selectList(this.getNamespace() + "selectYxtJiaoFuResGradeList", map);
	}
	
	public List<YxtJiaoFuResVo> getYxtJiaoFuCourse(String schoolid,String grade ,int f_ccc_catalogid) {
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("schoolid", schoolid);
		map.put("grade", grade);
		map.put("f_ccc_catalogid", f_ccc_catalogid); 
		return getSqlSession().selectList(this.getNamespace() + "selectYxtJiaoFuResCourseList", map);
	}
	
	public int getYxtJiaoFuResCount(String schoolid,String grade,String course,int f_ccc_catalogid) {
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("schoolid", schoolid);
		map.put("grade", grade);
		map.put("course", course);
		map.put("f_ccc_catalogid", f_ccc_catalogid); 
		return getSqlSession().selectOne(this.getNamespace() + "selectYxtJiaoFuResListCount", map);
	}
	public List<YxtJiaoFuResVo> getYxtJiaoFuRes(String schoolid,String grade,String course,int f_ccc_catalogid,int pageNo,int pageSize) {
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("schoolid", schoolid);
		map.put("f_ccc_catalogid", f_ccc_catalogid); 
		map.put("grade", grade);
		map.put("course", course);
		map.put("pageNo", pageNo);
		map.put("pageSize", pageSize);
		return getSqlSession().selectList(this.getNamespace() + "selectYxtJiaoFuResList", map);
	}
	public List<YxtLuBoResVo> getYxtLuBoResClassList(String schoolid,int f_ccc_catalogid) {
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("schoolid", schoolid);
		map.put("f_ccc_catalogid", f_ccc_catalogid); 
		return getSqlSession().selectList(this.getNamespace() + "selectYxtLuBoResClassList", map);
	}
	public List<YxtLuBoResVo> getYxtLuBoResCourse(String schoolid,String classid, int f_ccc_catalogid) {
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("schoolid", schoolid);
		map.put("classid", classid);
		map.put("f_ccc_catalogid", f_ccc_catalogid);
		return getSqlSession().selectList(this.getNamespace() + "selectYxtLuBoResCourseList", map);
	}
	public int getYxtLuBoResCount(String schoolid,String classid,String course, int f_ccc_catalogid) {
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("schoolid", schoolid);
		map.put("classid", classid);
		map.put("course", course);
		map.put("f_ccc_catalogid", f_ccc_catalogid);
		return getSqlSession().selectOne(this.getNamespace() + "selectYxtLuBoResListCount", map);
	}
	public List<YxtLuBoResVo> getYxtLuBoRes(String schoolid,String classid,String course,int f_ccc_catalogid,int pageNo,int pageSize) {
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("schoolid", schoolid);
		map.put("classid", classid);
		map.put("course", course);
		map.put("f_ccc_catalogid", f_ccc_catalogid);
		map.put("pageNo", pageNo);
		map.put("pageSize", pageSize);
		return getSqlSession().selectList(this.getNamespace() + "selectYxtLuBoResList", map);
	}
	
	public int getYxtAlbumResCount(String schoolid,String f_ya_albumtype,String f_ya_areacode,String f_ya_gradetype,String f_ya_gradeid,String f_ya_subjectid){
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("f_ya_albumtype", f_ya_albumtype);	
		map.put("f_ya_areacode", f_ya_areacode);
		map.put("f_ya_schoolid", schoolid);
		map.put("f_ya_gradetype", f_ya_gradetype);	
		map.put("f_ya_gradeid", f_ya_gradeid);
		map.put("f_ya_subjectid", f_ya_subjectid);
		return getSqlSession().selectOne(this.getNamespace() + "selectYxtAlbumResCount", map);
	}
	public List<YxtAlbumVo> getYxtAlbumResList(String schoolid,String f_ya_albumtype,String f_ya_areacode,String f_ya_gradetype,String f_ya_gradeid,String f_ya_subjectid,int pageNo,int pageSize){
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("f_ya_albumtype", f_ya_albumtype);
		map.put("f_ya_areacode", f_ya_areacode);
		map.put("f_ya_schoolid", schoolid);
		map.put("f_ya_gradetype", f_ya_gradetype);	
		map.put("f_ya_gradeid", f_ya_gradeid);
		map.put("f_ya_subjectid", f_ya_subjectid);
		map.put("pageNo", pageNo);
		map.put("pageSize", pageSize);
		return getSqlSession().selectList(this.getNamespace() + "selectYxtAlbumYuResList", map);
	}
	public int getYxtAlbumResContentCount(String schoolid,String f_yjr_entry,String f_yjr_albumlistid,int f_ccc_catalogid){
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("f_yjr_albumlistid", f_yjr_albumlistid);		
		map.put("f_ccc_catalogid", f_ccc_catalogid);
		map.put("f_yjr_entry", f_yjr_entry);
		map.put("f_yjr_schoolid", schoolid);
		return getSqlSession().selectOne(this.getNamespace() + "selectYxtAlbumResContenCount", map);
	}
	public List<YxtJiaoFuResVo> getYxtAlbumResContentList(String schoolid,String f_yjr_albumlistid,String f_yjr_entry,int f_ccc_catalogid,int pageNo,int pageSize){
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("f_yjr_albumlistid", f_yjr_albumlistid);		
		map.put("f_ccc_catalogid", f_ccc_catalogid);
		map.put("f_yjr_entry", f_yjr_entry);
		map.put("f_yjr_schoolid", schoolid);
		map.put("pageNo", pageNo);
		map.put("pageSize", pageSize);
		return getSqlSession().selectList(this.getNamespace() + "selectYxtAlbumResContentList", map);
	}
	public int insertContent(CmContentVo cmContentVo){
		try {
			getSqlSession().insert(this.getNamespace() + "insertContent", cmContentVo);
			Map<String, Object> map1=new HashMap<String, Object>();
			map1.put("f_cc_id", cmContentVo.getF_cc_id());
			map1.put("f_cco_orgId", cmContentVo.getF_cco_orgId());
			getSqlSession().insert(this.getNamespace() + "insertContentOrg", map1);
			Map<String, Object> map=new HashMap<String, Object>();
			map.put("f_ccc_catalogid", "18");//绑定业务账号到业务账号分类
			map.put("f_ccc_contentid", cmContentVo.getF_cc_id());
			map.put("f_ccc_viewindex", 1);
			map.put("f_cco_orgId", cmContentVo.getF_cco_orgId());
			getSqlSession().insert(this.getNamespace() + "insertCatalogContent", map);
			return 1;
		} catch (Exception e) {
			LOG.error("视频插入内容失败",e);
			return 0;
		}
	}

	public PmsOrgVo selectOrgVo(int f_po_id) {
		return getSqlSession().selectOne(this.getNamespace() + "selectOrgVo", f_po_id);
	}

	public List<YxtAlbumVo> getYxtAlbumGradeType(String schoolid,
			String f_ya_albumtype, String f_ya_areacode) {
			Map<String,Object> map = new HashMap<String, Object>();
			map.put("f_ya_albumtype", f_ya_albumtype);	
			map.put("f_ya_areacode", f_ya_areacode);
			map.put("f_ya_schoolid", schoolid);
		return getSqlSession().selectList(this.getNamespace() + "selectYxtAlbumGradeType", map);
	}

	public List<YxtAlbumVo> getYxtAlbumGradeId(String schoolid,
			String f_ya_albumtype, String f_ya_areacode, String f_ya_gradetype) {
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("f_ya_albumtype", f_ya_albumtype);	
		map.put("f_ya_areacode", f_ya_areacode);
		map.put("f_ya_schoolid", schoolid);
		map.put("f_ya_gradetype", f_ya_gradetype);
	return getSqlSession().selectList(this.getNamespace() + "selectYxtAlbumGradeId", map);
	}

	public List<YxtAlbumVo> getYxtAlbumSubjectId(String schoolid,
			String f_ya_albumtype, String f_ya_areacode, String f_ya_gradetype,
			String f_ya_gradeid) {
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("f_ya_albumtype", f_ya_albumtype);	
		map.put("f_ya_areacode", f_ya_areacode);
		map.put("f_ya_schoolid", schoolid);
		map.put("f_ya_gradetype", f_ya_gradetype);
		map.put("f_ya_gradeid", f_ya_gradeid);
	return getSqlSession().selectList(this.getNamespace() + "selectYxtAlbumSubjectId", map);
	}

	public List<CmContentVo> selectNoticeList(String userId, int f_catalog_id, int f_po_id,int f_ym_type,
			int pageNo, int pageSize) {
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("f_ym_userid", userId);	
		map.put("f_catalog_id", f_catalog_id);
		map.put("f_cco_orgId", f_po_id);
		map.put("f_ym_type", f_ym_type);
		map.put("firstResult", pageNo);
		map.put("pageSize", pageSize);
	return getSqlSession().selectList(this.getNamespace() + "selectNoticeList", map);
	}

	public int selectNoticeListCount(String userId, int f_catalog_id,
			int f_po_id,int f_ym_type) {
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("f_ym_userid", userId);	
		map.put("f_catalog_id", f_catalog_id);
		map.put("f_cco_orgId", f_po_id);
		map.put("f_ym_type", f_ym_type);
	return getSqlSession().selectOne(this.getNamespace() + "selectNoticeListCount", map);
	}

	public List<CmContentVo> selectSmsList(String userId, int f_catalog_id,int f_ym_type,
			int pageNo, int pageSize) {
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("f_ym_userid", userId);	
		map.put("f_catalog_id", f_catalog_id);
		map.put("f_ym_type", f_ym_type);
		map.put("firstResult", pageNo);
		map.put("pageSize", pageSize);
		return getSqlSession().selectList(this.getNamespace() + "selectSmsList", map);
	}

	public int selectSmsListCount(String userId, int f_catalog_id, int f_ym_type) {
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("f_ym_userid", userId);	
		map.put("f_catalog_id", f_catalog_id);
		map.put("f_ym_type", f_ym_type);
		return getSqlSession().selectOne(this.getNamespace() + "selectSmsListCount", map);
	}

	public YxtSchoolVo selectYxtSchoolInfo(String schoolid) {
		return getSqlSession().selectOne(this.getNamespace() + "selectYxtSchoolInfo", schoolid);
	}
	public int selectCatalogInfoListByParentCatalogIdCount(int f_catalog_id) {
		return getSqlSession().selectOne(this.getNamespace() + "selectCatalogInfoListByParentCatalogIdCountOld", f_catalog_id);
	}
	public List<CmCatalogVo> selectCatalogInfoListByParentCatalogId(int f_catalog_id,int pageNo,int pageSize) {
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("f_catalog_id", f_catalog_id);
		map.put("firstResult", pageNo);
		map.put("pageSize", pageSize);
		return getSqlSession().selectList(this.getNamespace() + "selectCatalogInfoListByParentCatalogIdOld", map);
	}
	public int updatePmsOrgDesc(PmsOrgVo orgVo) {
		return getSqlSession().update(this.getNamespace() + "updatePmsOrgDesc", orgVo);
	}

	public List<YxtMsSpzxVo> selectAllSpzx(String stage, String course, int pageNo, int pageSize) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("f_yms_stage", stage);
		map.put("f_yms_coursecategory", course);
		map.put("pageNo", pageNo);
		map.put("pageSize", pageSize);
		
		return getSqlSession().selectList(this.getNamespace() + "selectAllSpzx",map);
	}

	public List<YxtMsMskcVo> selectAllMskc(int pageNo, int pageSize) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("pageNo", pageNo);
		map.put("pageSize", pageSize);
		
		return getSqlSession().selectList(this.getNamespace() + "selectAllMskc",map);
	}

	public List<YxtMsSpzxVo> selectCoursefromStage(String stage) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("stage", stage);
		
		return getSqlSession().selectList(this.getNamespace() + "selectCoursefromStage",map);

	}

	public List<YxtMsMskcVo> getContentForMskc(String f_ykc_courseid, int pageNo, int pageSize) {
		Map<String,Object> map =new  HashMap<String, Object>();
		map.put("f_ykc_courseid", f_ykc_courseid);
		map.put("pageNo", pageNo);
		map.put("pageSize", pageSize);
		return getSqlSession().selectList(this.getNamespace() + "getContentForMskc",map);
	}

	public YxtMsSpzxVo selectMsSpzxformId(int f_yms_id) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("f_yms_id", f_yms_id);
		return getSqlSession().selectOne(this.getNamespace() + "selectMsSpzxformId",map);
	}

	public int insertCollectByAlbum(YxtMsCollectVo collectVo) {
		
		return getSqlSession().insert(this.getNamespace() + "insertCollectByAlbum",collectVo);
	}

	public List<UserHistoryVo> selectPlayRecord(UserHistoryVo userHistoryVo) {
		return getSqlSession().selectList(this.getNamespace() + "selectPlayRecord",userHistoryVo);
	}

	public List<YxtMsCollectVo> selectCollect(String f_ysc_user_id) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("f_ysc_user_id", f_ysc_user_id);
		
		return getSqlSession().selectList(this.getNamespace() + "selectCollect",map);
	}

	public int deleteMsykAlbum(YxtMsCollectVo collectVo) {
		Map<String,Object> map = new HashMap<>();
		map.put("f_ysc_superior_id", collectVo.getF_ysc_superior_id());
		map.put("f_ysc_user_id", collectVo.getF_ysc_user_id());
		return getSqlSession().delete(this.getNamespace() + "deleteMsykAlbum", map);
	}

	public List<YxtNmsykMenuVo> selectNmsykMenu(YxtNmsykMenuVo menuVo) {
		Map<String,Object> map = new HashMap<>();
		map.put("f_ynm_type", menuVo.getF_ynm_type());
		map.put("f_ynm_stage", menuVo.getF_ynm_stage());
		return getSqlSession().selectList(this.getNamespace() + "selectNmsykMenu",map);
	}

	public List<YxtNmsykLessonVo> selectLseeonFromId(YxtNmsykCourseVo courseVo) {
		return getSqlSession().selectList(this.getNamespace() + "selectLseeonFromId",courseVo);
	}

	public YxtNmsykCourseVo selectCourseById(YxtNmsykCourseVo courseVo) {
		
		return getSqlSession().selectOne(this.getNamespace() + "selectCourseById",courseVo);
	}

	public SysConfigVo selectSysByKey(String confing_name) {
		Map<String, String> map = new HashMap<String, String>();
		map.put("f_sc_key", confing_name);
		return getSqlSession().selectOne(this.getNamespace() + "selectSysByKey",map);
	}

	public int insertMsykContent(CmContentVo cmContentVo) {
		try {
			getSqlSession().insert(this.getNamespace() + "insertContent", cmContentVo);//添加cotent
			Map<String, Object> map1=new HashMap<String, Object>();
			map1.put("f_cc_id", cmContentVo.getF_cc_id());
			map1.put("f_cco_orgId", 1);
			getSqlSession().insert(this.getNamespace() + "insertContentOrg", map1);
			Map<String, Object> map=new HashMap<String, Object>();
			map.put("f_ccc_catalogid", "1312");//跟名师优课分类绑定在一起
			map.put("f_ccc_contentid", cmContentVo.getF_cc_id());
			map.put("f_ccc_viewindex", 1);
			map.put("f_cco_orgId", 1);
			getSqlSession().insert(this.getNamespace() + "insertCatalogContent", map);
			return 1;
		} catch (Exception e) {
			LOG.error("名师优课绑定失败",e);
			return 0;
		}
	}

	public YxtNmsykLessonVo selectLseeonByContentId(YxtNmsykCourseVo courseVo) {
		return getSqlSession().selectOne(this.getNamespace() + "selectLseeonByContentId",courseVo);
	}

	public CmContentVo selectContentbyId(String f_ynl_old_id) {
		Map<String, String> map = new HashMap<>();
		map.put("f_ynl_old_id", f_ynl_old_id);
		
		return getSqlSession().selectOne(this.getNamespace() + "selectContentbyId",map);
	}

	public YxtNmsykCourseVo selectCourseByContent(String  f_ynl_content_id) {
		Map<String, String> map =new HashMap<>();
		map.put("f_ynl_content_id", f_ynl_content_id);
		return getSqlSession().selectOne(this.getNamespace() + "selectCourseByContent",map);
	}

	public List<YxtNmsykCourseVo> selectCourse(YxtNmsykCourseVo courseVo) {
		return getSqlSession().selectList(this.getNamespace() + "selectCourse", courseVo);
	}

	public List<YxtNmsykCourseVo> selectCourseBySearch(YxtNmsykCourseVo courseVo) {
		return getSqlSession().selectList(this.getNamespace() + "selectCourseBySearch", courseVo);
	}

	public List<YxtNmsykTopTeacherVo> selectTopTeacher(YxtNmsykTopTeacherVo yxtNmsykTopTeacherVo) {
		return getSqlSession().selectList(this.getNamespace() + "selectTopTeacher", yxtNmsykTopTeacherVo);
	}

	public int selectNotViewedCount(String f_nmcr_user_phone,String f_nmcc_filetype,String f_uvh_serverid,String riqi){
		Map<String, String> map =new HashMap<>();
		map.put("f_nmcr_user_phone", f_nmcr_user_phone);
		map.put("f_nmcc_filetype", f_nmcc_filetype);
		map.put("f_uvh_serverid", f_uvh_serverid);
		map.put("riqi", riqi);
		return getSqlSession().selectOne(this.getNamespace() + "selectNotViewedCount",map);
	}

	public List<YxtNmsykClassRoomCourseVo> selectLLClassRoom(String f_yai_phone, String f_nmcc_subject, String f_nmcc_filetype, int page,
			int rows) {
		Map<String,Object > map = new HashMap<>();
		map.put("f_nmcr_user_phone", f_yai_phone);
		map.put("f_nmcc_subject", f_nmcc_subject);
		map.put("f_nmcc_filetype", f_nmcc_filetype);
		map.put("pageNo", page);
		map.put("pageSize", rows);
		
		return getSqlSession().selectList(this.getNamespace() + "selectLLClassRoom", map);
	}

	public CmContentVo selectContentByContentId(CmContentVo cmContentVo) {
		return getSqlSession().selectOne(this.getNamespace() + "selectContentByContentId",cmContentVo);
	}
}

